<template>
  <div>
    <h2><slot></slot></h2>

    <p>{{ myCounter }}</p>
    <p>{{ counter }}</p>
    <p>{{ counter2 }}</p>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'State2',
  computed: {
    // state → 组件的 computed
    myCounter() {
      return this.$store.state.counter
    },

    // mapState
    ...mapState(['counter']),

    // mapState 重命名
    ...mapState({
      counter2: 'counter'
    })
  }
}
</script>
